#!/bin/bash
# 环境变量 package_path service_version service_name
REPOSITORY=registry-cbu.huawei.com
ORG=saaslanding
CID_REPO_COMMIT=$(git rev-parse --short HEAD)
artifactTag=$(date '+%Y%m%d%H%M%S')
TAG=${artifactTag}.${CID_BUILD_TIME}.${CID_BUILD_NUMBER}


saaslanding_service_name=${1}

# 组件根目录
saaslanding_root_dir=$(
  cd $(dirname $0)/
  pwd
)


# 在构建saaslanding-demo-ui
echo ${saaslanding_root_dir}
cd ${saaslanding_root_dir}

function main() {
  npm install
  npm run build
  tar -cvf dist.tar dist/
  mkdir -p .build_config
  echo "${REPOSITORY}/${ORG}/${saaslanding_service_name}:${TAG}" >.build_config/imageVersion.text
  echo -e "build_time:$(date --rfc-3339=seconds)\nbuild_branch:$(git rev-parse --abbrev-ref HEAD)\nbuild_commit:$(git rev-parse HEAD)" >build.version
  ls -ltra
  cat .build_config/imageVersion.text
  docker build -t ${REPOSITORY}/${ORG}/${saaslanding_service_name}:${TAG} -f ./Dockerfile .
}
main
